home *** CD-ROM | disk | FTP | other *** search
/ PC Basics 53 / PC Basics Issue 53.iso / Software / Internet / Invboard.exe / PC Basics 53 / Invboard / upload / sources / Admin / admin_functions.php < prev    next >
Encoding:
PHP Script  |  2002-06-12  |  12.0 KB  |  532 lines

  1. <?php
  2.  
  3. /*
  4. +--------------------------------------------------------------------------
  5. |   IBFORUMS v1
  6. |   ========================================
  7. |   by Matthew Mecham and David Baxter
  8. |   (c) 2001,2002 IBForums
  9. |   http://www.ibforums.com
  10. |   ========================================
  11. |   Web: http://www.ibforums.com
  12. |   Email: phpboards@ibforums.com
  13. |   Licence Info: phpib-licence@ibforums.com
  14. +---------------------------------------------------------------------------
  15. |
  16. |   > Admin functions library
  17. |   > Script written by Matt Mecham
  18. |   > Date started: 1st march 2002
  19. |
  20. +--------------------------------------------------------------------------
  21. */
  22.  
  23.  
  24. class admin_functions {
  25.  
  26.     var $img_url;
  27.     var $page_title  = "Welcome to the Invision Board Administration CP";
  28.     var $page_detail = "You can set up and customize your board from within this control panel.<br><br>Clicking on one of the links in the left menu pane will show you the relevant options for that administration category. Each option will contain further information on configuration, etc.";
  29.     var $html;
  30.     var $errors = "";
  31.  
  32.     function admin_functions() {
  33.         global $INFO, $IN;
  34.         
  35.         $this->img_url = $INFO['html_url'].'/sys-img';
  36.         $this->base_url = $INFO['board_url']."/admin.".$INFO['php_ext']."?adsess=".$IN['AD_SESS'];
  37.         
  38.     }
  39.     
  40.     //**********************************************/
  41.     // get_tar_names
  42.     //
  43.     // Simply returns a list of tarballs that start
  44.     // with the given filename
  45.     //**********************************************/
  46.     
  47.     function get_tar_names($start='lang-')
  48.     {
  49.         global $INFO;
  50.         
  51.         // Remove trailing slashes..
  52.         
  53.         $files = array();
  54.         
  55.         $dir = $INFO['base_dir']."archive_in";
  56.             
  57.         if ( is_dir($dir) )
  58.         {
  59.             $handle = opendir($dir);
  60.             
  61.             while (($filename = readdir($handle)) !== false)
  62.             {
  63.                 if (($filename != ".") && ($filename != ".."))
  64.                 {
  65.                     if (preg_match("/^$start.+?\.tar$/", $filename))
  66.                     {
  67.                         $files[] = $filename;
  68.                     }
  69.                 }
  70.             }
  71.             
  72.             closedir($handle);
  73.             
  74.         }
  75.         
  76.         return $files;
  77.             
  78.     }
  79.     
  80.     //**********************************************/
  81.     // copy_dir
  82.     //
  83.     // Copies to contents of a dir to a new dir, creating
  84.     // destination dir if needed.
  85.     //
  86.     //**********************************************/
  87.     
  88.     function copy_dir($from_path, $to_path, $mode = 0777)
  89.     {
  90.     
  91.         global $INFO;
  92.         
  93.         // Strip off trailing slashes...
  94.         
  95.         $from_path = preg_replace( "#/$#", "", $from_path);
  96.         $to_path   = preg_replace( "#/$#", "", $to_path);
  97.     
  98.         if ( ! is_dir($from_path) )
  99.         {
  100.             $this->errors = "Could not locate directory '$from_path'";
  101.             return FALSE;
  102.         }
  103.     
  104.         if ( ! is_dir($to_path) )
  105.         {
  106.             if ( ! @mkdir($to_path, $mode) )
  107.             {
  108.                 $this->errors = "Could not create directory '$to_path' please check the CHMOD permissions and re-try";
  109.                 return FALSE;
  110.             }
  111.             else
  112.             {
  113.                 @chmod($to_path, $mode);
  114.             }
  115.         }
  116.         
  117.         $this_path = getcwd();
  118.         
  119.         if (is_dir($from_path))
  120.         {
  121.             chdir($from_path);
  122.             $handle=opendir('.');
  123.             while (($file = readdir($handle)) !== false)
  124.             {
  125.                 if (($file != ".") && ($file != ".."))
  126.                 {
  127.                     if (is_dir($file))
  128.                     {
  129.                         
  130.                         $this->copy_dir($from_path."/".$file, $to_path."/".$file);
  131.                         
  132.                         chdir($from_path);
  133.                     }
  134.                     
  135.                     if ( is_file($file) )
  136.                     {
  137.                         copy($from_path."/".$file, $to_path."/".$file);
  138.                         @chmod($to_path."/".$file, 0777);
  139.                     } 
  140.                 }
  141.             }
  142.             closedir($handle); 
  143.         }
  144.         
  145.         if ($this->errors == "")
  146.         {
  147.             return TRUE;
  148.         }
  149.     }
  150.     
  151.     //**********************************************/
  152.     // rm_dir
  153.     //
  154.     // Removes directories, if non empty, removes
  155.     // content and directories
  156.     // (Code based on annotations from the php.net
  157.     // manual by pal@degerstrom.com)
  158.     //**********************************************/
  159.     
  160.     function rm_dir($file)
  161.     {
  162.         global $INFO;
  163.         
  164.         $errors = 0;
  165.         
  166.         // Remove trailing slashes..
  167.         
  168.         $file = preg_replace( "#/$#", "", $file );
  169.         
  170.         if ( file_exists($file) )
  171.         {
  172.             // Attempt CHMOD
  173.             
  174.             @chmod($file, 0777);
  175.             
  176.             if ( is_dir($file) )
  177.             {
  178.                 $handle = opendir($file);
  179.                 
  180.                 while (($filename = readdir($handle)) !== false)
  181.                 {
  182.                     if (($filename != ".") && ($filename != ".."))
  183.                     {
  184.                         $this->rm_dir($file."/".$filename);
  185.                     }
  186.                 }
  187.                 
  188.                 closedir($handle);
  189.                 
  190.                 if ( ! @rmdir($file) )
  191.                 {
  192.                     $errors++;
  193.                 }
  194.             }
  195.             else
  196.             {
  197.                 if ( ! @unlink($file) )
  198.                 {
  199.                     $errors++;
  200.                 }
  201.             }
  202.         }
  203.         
  204.         if ($errors == 0)
  205.         {
  206.             return TRUE;
  207.         }
  208.         else
  209.         {
  210.             return FALSE;
  211.         }
  212.     }
  213.     
  214.     //**********************************************/
  215.     // rebuild_config:
  216.     //
  217.     // Er, rebuilds the config file
  218.     //
  219.     //**********************************************/
  220.     
  221.     function rebuild_config( $new = "" )
  222.     {
  223.         global $IN, $std, $root_path;
  224.         
  225.         //-----------------------------------------
  226.         // Check to make sure this is a valid array
  227.         //-----------------------------------------
  228.         
  229.         if (! is_array($new) )
  230.         {
  231.             $ADMIN->error("Error whilst attempting to rebuild the board config file, attempt aborted");
  232.         }
  233.         
  234.         //-----------------------------------------
  235.         // Do we have anything to save out?
  236.         //-----------------------------------------
  237.         
  238.         if ( count($new) < 1 )
  239.         {
  240.             return "";
  241.         }
  242.         
  243.         //-----------------------------------------
  244.         // Get an up to date copy of the config file
  245.         // (Imports $INFO)
  246.         //-----------------------------------------
  247.         
  248.         require $root_path.'conf_global.php';
  249.         
  250.         //-----------------------------------------
  251.         // Rebuild the $INFO hash
  252.         //-----------------------------------------
  253.         
  254.         foreach( $new as $k => $v )
  255.         {
  256.             // Update the old...
  257.             
  258.             $v = preg_replace( "/'/", "\\'" , $v );
  259.             $v = preg_replace( "/\r/", ""   , $v );
  260.             
  261.             $INFO[ $k ] = $v;
  262.         }    
  263.         
  264.         //-----------------------------------------
  265.         // Rename the old config file
  266.         //-----------------------------------------
  267.         
  268.         @rename( $root_path.'conf_global.php', $root_path.'conf_global-bak.php' );
  269.         @chmod( $root_path.'conf_global-bak.php', 0777);
  270.         
  271.         //-----------------------------------------
  272.         // Rebuild the old file
  273.         //-----------------------------------------
  274.         
  275.         $file_string = "<?php\n";
  276.         
  277.         foreach( $INFO as $k => $v )
  278.         {
  279.             if ($k == 'skin' or $k == 'languages')
  280.             {
  281.                 // Protect serailized arrays..
  282.                 $v = stripslashes($v);
  283.                 $v = addslashes($v);
  284.             }
  285.             $file_string .= '$INFO['."'".$k."'".']'."\t\t\t=\t'".$v."';\n";
  286.         }
  287.         
  288.         $file_string .= "\n".'?'.'>';   // Question mark + greater than together break syntax hi-lighting in BBEdit 6 :p
  289.         
  290.         if ( $fh = fopen( $root_path.'conf_global.php', 'w' ) )
  291.         {
  292.             fputs ($fh, $file_string, strlen($file_string) );
  293.             fclose($fh);
  294.         }
  295.         else
  296.         {
  297.             $ADMIN->error("Fatal Error: Could not open conf_global for writing - no changes applied. Try changing the CHMOD to 0777");
  298.         }
  299.         
  300.         // Pass back the new $INFO array to anyone who cares...
  301.         
  302.         return $INFO;
  303.         
  304.     }
  305.     
  306.     //**********************************************/
  307.     // compile_forum_perms:
  308.     //
  309.     // Returns the READ/REPLY/START DB strings
  310.     //
  311.     //**********************************************/
  312.     
  313.     
  314.     function compile_forum_perms() {
  315.         global $DB, $IN;
  316.         
  317.         $r_array = array( 'READ' => '', 'REPLY' => '', 'START' => '' );
  318.         
  319.         if ($IN['READ_ALL'] == 1)
  320.         {
  321.             $r_array['READ'] = '*';
  322.         }
  323.         
  324.         if ($IN['REPLY_ALL'] == 1)
  325.         {
  326.             $r_array['REPLY'] = '*';
  327.         }
  328.         
  329.         if ($IN['START_ALL'] == 1)
  330.         {
  331.             $r_array['START'] = '*';
  332.         }
  333.         
  334.         
  335.         
  336.         $DB->query("SELECT g_id, g_title FROM ibf_groups ORDER BY g_id");
  337.              
  338.         while ( $data = $DB->fetch_row() )
  339.         {
  340.             if ($r_array['READ'] != '*')
  341.             {
  342.                 if ($IN[ 'READ_'.$data['g_id'] ] == 1)
  343.                 {
  344.                     $r_array['READ'] .= $data['g_id'].",";
  345.                 }
  346.             }
  347.             //+----------------------------
  348.             if ($r_array['REPLY'] != '*')
  349.             {
  350.                 if ($IN[ 'REPLY_'.$data['g_id'] ] == 1)
  351.                 {
  352.                     $r_array['REPLY'] .= $data['g_id'].",";
  353.                 }
  354.             }
  355.             //+----------------------------
  356.             if ($r_array['START'] != '*')
  357.             {
  358.                 if ($IN[ 'START_'.$data['g_id'] ] == 1)
  359.                 {
  360.                     $r_array['START'] .= $data['g_id'].",";
  361.                 }
  362.             }
  363.         }
  364.         
  365.         $r_array['START'] = preg_replace( "/,$/", "", $r_array['START'] );
  366.         $r_array['REPLY'] = preg_replace( "/,$/", "", $r_array['REPLY'] );
  367.         $r_array['READ']  = preg_replace( "/,$/", "", $r_array['READ']  );
  368.         
  369.         return $r_array;
  370.         
  371.     }
  372.     
  373.     
  374.     //+------------------------------------------------
  375.     //+------------------------------------------------
  376.     // OUTPUT FUNCTIONS
  377.     //+------------------------------------------------
  378.     //+------------------------------------------------
  379.     
  380.     
  381.     function output() {
  382.         global $IN, $INFO, $DB, $std, $SKIN, $use_gzip;
  383.     
  384.         $html  = $SKIN->print_top($this->page_title, $this->page_detail);
  385.         $html .= $this->html;
  386.         $html .= $SKIN->print_foot();
  387.         
  388.         $DB->close_db();
  389.         
  390.         if ($use_gzip == 1)
  391.         {
  392.             ob_start ('ob_gzhandler');
  393.         }
  394.         
  395.         //@header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  396.         //@header("Cache-Control: no-cache, must-revalidate");
  397.         //@header("Pragma: no-cache");
  398.                 
  399.         print $html;
  400.         
  401.         exit();
  402.     
  403.     }
  404.     
  405.     //**********************************************/
  406.     // Error:
  407.     //
  408.     // Displays an error
  409.     //
  410.     //**********************************************/
  411.     
  412.     function error($error="") {
  413.         global $IN, $INFO, $DB, $std, $SKIN, $HTTP_REFERER;
  414.         
  415.         $this->page_title  = "An Error Occured...";
  416.         $this->page_detail = "The error message returned is displayed below.";
  417.         
  418.         $this->html .= "<tr><td><span style='font-size:14px'>$error</span><br><br><center><a href='$HTTP_REFERER'>Go Back</a></center></td></tr>";
  419.         
  420.         $this->output();
  421.         
  422.     }
  423.     
  424.     //**********************************************/
  425.     // Done Screen:
  426.     //
  427.     // Displays the "done" screen. Really? Yes.
  428.     //
  429.     //**********************************************/
  430.     
  431.     function done_screen($title, $link_text="", $link_url="") {
  432.         global $IN, $INFO, $DB, $std, $SKIN;
  433.         
  434.         $this->page_title  = $title;
  435.         $this->page_detail = "The action was executed successfully";
  436.         
  437.         $SKIN->td_header[] = array( " "  , "100%" );
  438.         
  439.         $this->html .= $SKIN->start_table("Result");
  440.         
  441.         $this->html .= $SKIN->add_td_basic( "<a href='{$this->base_url}&{$link_url}' target='body'>Go to: $link_text</a>", "center" );
  442.         
  443.         $this->html .= $SKIN->add_td_basic( "<a href='{$this->base_url}&act=index' target='body'>Go to: Administration Home</a>", "center" );
  444.                                          
  445.         $this->html .= $SKIN->end_table();
  446.             
  447.         $this->output();
  448.     
  449.     }
  450.     
  451.     function info_screen($text="", $title='Safe Mode Restriction Warning') {
  452.         global $IN, $INFO, $DB, $std, $SKIN;
  453.         
  454.         $this->page_title  = $title;
  455.         $this->page_detail = "Please note the following:";
  456.         
  457.         $SKIN->td_header[] = array( " "  , "100%" );
  458.         
  459.         $this->html .= $SKIN->start_table("Result");
  460.         
  461.         $this->html .= $SKIN->add_td_basic( $text );
  462.         
  463.         $this->html .= $SKIN->add_td_basic( "<a href='{$this->base_url}&act=index' target='body'>Go to: Administration Home</a>", "center" );
  464.                                          
  465.         $this->html .= $SKIN->end_table();
  466.             
  467.         $this->output();
  468.     
  469.     }
  470.     
  471.     
  472.     //**********************************************/
  473.     // MENU:
  474.     //
  475.     // Build the collapsable menu trees
  476.     //
  477.     //**********************************************/
  478.     
  479.     function menu() {
  480.         global $IN, $std, $PAGES, $CATS, $SKIN;
  481.         
  482.         $links = $this->build_tree();
  483.         
  484.         $html = $SKIN->menu_top() . $links . $SKIN->menu_foot();
  485.                          
  486.         print $html;
  487.         exit();
  488.  
  489.         
  490.     }
  491.     
  492.     //+------------------------------------------------
  493.     
  494.     function build_tree() {
  495.         global $IN, $std, $PAGES, $CATS, $SKIN, $DESC;
  496.         
  497.         $html  = "";
  498.         $links = "";
  499.         
  500.         foreach($CATS as $cid => $name)
  501.         {
  502.             
  503.             if ( preg_match( "/(?:^|,)$cid(?:,|$)/", $IN['show'] ) )
  504.             {
  505.             
  506.                   foreach($PAGES[ $cid ] as $pid => $pdata)
  507.                   {
  508.                       $links .= $SKIN->menu_cat_link($pdata[1], $pdata[0]);
  509.                   }
  510.                   
  511.                   $html .= $SKIN->menu_cat_expanded( $name, $links, $cid );
  512.                   unset($links);
  513.             
  514.             }
  515.             else
  516.             {
  517.                 $html .= $SKIN->menu_cat_collapsed( $name, $cid, $DESC[ $cid ] );
  518.             }
  519.         }
  520.         
  521.         return $html;
  522.         
  523.     }
  524.     
  525.     
  526. }
  527.  
  528.  
  529.  
  530.  
  531.  
  532. ?>